import sys
import MySQL
import Events
import People
import datetime



class TripExpenseAcceptSatus:
    def __init__(self, SQLConn, dBName = "TripExpenseAccept"):
        self.SQLConn = SQLConn
        self.dbName = dBName
        
    def AddPersonExpenseStatus(self, PID, EID, EXPID, STATUS):
        self.SQLConn.SendCommand("""
         INSERT INTO %s (PID, EID, EXPID, STATUS)
         VALUES ('%d', '%d', '%d', '%d')
       """ %(self.dbName, PID, EID, EXPID, STATUS))
    
    def RemovePID_EID(self, PID, EID):
        self.SQLConn.SendCommand("""    
         DELETE FROM %s where EID=%d AND PID=%d
         """ % (self.dbName, EID,PID))
        
    def RemoveEvent(self, EID):
        self.SQLConn.SendCommand("""    
         DELETE FROM %s where PID=%d
         """ % (self.dbName, EID))
        
    def UpdateEventPeople(self, EID, PID, EXPID, STATUS):
       self.SQLConn.SendCommand("""UPDATE %s
                                SET STATUS = '%d'
                                WHERE PID = %d
                                AND EID = %d
                                AND EXPID = %d
                                """ % (self.dbName, STATUS, PID, EID, EXPID))
       
    def GetPersonsAccepts(self, PID, EID):
        self.SQLConn.SendCommand("""SELECT EXPID, STATUS FROM %s WHERE PID = %d AND EID = %d"""%(self.dbName, PID, EID))
        rows = self.SQLConn.FetchAll ()
        Status = {}
        for Res in rows:
            Status[Res[0]] = Res[1]
        return Status
       
    
if __name__ == '__main__':
    SQL = MySQL.Connection()
    
        
    
    SQL.SendCommand ("DROP TABLE IF EXISTS TripExpenseAccept")
    SQL.SendCommand("""CREATE TABLE TripExpenseAccept(
                    EID int,
                    PID int,
                    EXPID int,
                    STATUS int)
                    """)



    #E = Events(SQL)
    #exit = False
    #while not exit:
    #    Input = raw_input("Now What? : ")
    #    if Input == 'exit':
    #        exit = True
    #    if Input == 'new':
    #        Event_Name = raw_input("Event Name : ")
    #        Event_Dates = raw_input("Event Dates : ")
    #        People = raw_input("People : ")
    #        E.AddEvent(Event_Name, Event_Dates, People)
    #        
    #    if Input == 'del':
    #        EID = int(raw_input("Number : "))
    #        E.RemoveEvent(EID)
    #        
    #    if Input == 'print':
    #        Ev =  E.GetAllEvents()
    #        for w in Ev:
    #            print w.EID, w.EventName, w.DateStr
    #            
    #    if Input == 'Update':
    #        ID = int(raw_input("EID : "))
    #        name = raw_input("name : ")
    #        E.UpdateEvent(ID, name)
    #        
    #print "Finished"
    #  
    #SQL.close()  
    #
    
    
  
    
        